package com.macaline.notion;

import net.sf.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class Test {

    public static String NOTION_API_KEY = "secret_yxdOtr9Vhfqv1KsGnooP5tnHudsvXqCad8mBvpzo43v";
    public static String NOTION_DATABASE_ID = "a159a8c44de64b4dbb8ed1e318139e56";

    static RestTemplate restTemplate = new RestTemplate();
    public static void main(String[] args) {

        queryPage();
//        queryPageInfo();

    }


    public static void queryPageInfo(){
        HttpHeaders headers = new HttpHeaders();
        JSONObject param = new JSONObject();
//        // 请求头
        headers.set("Authorization", "Bearer " + NOTION_API_KEY);
        headers.set("Content-Type", "application/json");
        headers.set("Notion-Version", "2022-06-28");
        // 请求头
        HttpEntity entity = new HttpEntity(headers);

        ResponseEntity<JSONObject> response = restTemplate.exchange("https://api.notion.com/v1/pages/2f412db2f9e84f5cbd14b1d51a05575d/properties/property_id", HttpMethod.GET, entity, JSONObject.class);
        System.out.println(response);
    }

    public static void queryPage(){



        HttpHeaders headers = new HttpHeaders();
        JSONObject param = new JSONObject();

//        // 请求头
        headers.set("Authorization", "Bearer " + NOTION_API_KEY);
        headers.set("Content-Type", "application/json");
        headers.set("Notion-Version", "2022-06-28");
        // 请求头
        HttpEntity entity = new HttpEntity(headers);


        ResponseEntity<JSONObject> response = restTemplate.exchange("https://api.notion.com/v1/pages/2f412db2f9e84f5cbd14b1d51a05575d", HttpMethod.GET, entity, JSONObject.class);
        System.out.println(response);
    }

}
